{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_path = r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\q2_b_cluster_4_record.xlsx'\n",
    "data = pd.read_excel(data_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>label</th>\n",
       "      <th>ED_volume</th>\n",
       "      <th>time_from_start</th>\n",
       "      <th>time_gap</th>\n",
       "      <th>y_pred</th>\n",
       "      <th>y_truth</th>\n",
       "      <th>diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>sub001</td>\n",
       "      <td>0</td>\n",
       "      <td>48919</td>\n",
       "      <td>330.548947</td>\n",
       "      <td>2.500000</td>\n",
       "      <td>53620.218750</td>\n",
       "      <td>48919.0</td>\n",
       "      <td>4701.218750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>sub001</td>\n",
       "      <td>0</td>\n",
       "      <td>57898</td>\n",
       "      <td>330.789294</td>\n",
       "      <td>8.268333</td>\n",
       "      <td>53566.015625</td>\n",
       "      <td>57898.0</td>\n",
       "      <td>-4331.984375</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>sub001</td>\n",
       "      <td>0</td>\n",
       "      <td>81747</td>\n",
       "      <td>335.949294</td>\n",
       "      <td>126.340000</td>\n",
       "      <td>52399.144531</td>\n",
       "      <td>81747.0</td>\n",
       "      <td>-29347.855469</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>sub001</td>\n",
       "      <td>0</td>\n",
       "      <td>107793</td>\n",
       "      <td>341.267176</td>\n",
       "      <td>130.129167</td>\n",
       "      <td>52359.496094</td>\n",
       "      <td>107793.0</td>\n",
       "      <td>-55433.503906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>sub001</td>\n",
       "      <td>0</td>\n",
       "      <td>126558</td>\n",
       "      <td>348.175544</td>\n",
       "      <td>168.300833</td>\n",
       "      <td>51968.328125</td>\n",
       "      <td>126558.0</td>\n",
       "      <td>-74589.671875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>sub099</td>\n",
       "      <td>3</td>\n",
       "      <td>19517</td>\n",
       "      <td>885.972986</td>\n",
       "      <td>17.672778</td>\n",
       "      <td>28701.111328</td>\n",
       "      <td>19517.0</td>\n",
       "      <td>9184.111328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>sub099</td>\n",
       "      <td>3</td>\n",
       "      <td>30933</td>\n",
       "      <td>887.008681</td>\n",
       "      <td>27.856667</td>\n",
       "      <td>28645.626953</td>\n",
       "      <td>30933.0</td>\n",
       "      <td>-2287.373047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>sub100</td>\n",
       "      <td>1</td>\n",
       "      <td>7367</td>\n",
       "      <td>786.766829</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>15922.395508</td>\n",
       "      <td>7367.0</td>\n",
       "      <td>8555.395508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>sub100</td>\n",
       "      <td>1</td>\n",
       "      <td>6033</td>\n",
       "      <td>788.193125</td>\n",
       "      <td>34.731111</td>\n",
       "      <td>15923.831055</td>\n",
       "      <td>6033.0</td>\n",
       "      <td>9890.831055</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>sub100</td>\n",
       "      <td>1</td>\n",
       "      <td>3191</td>\n",
       "      <td>794.964190</td>\n",
       "      <td>163.005556</td>\n",
       "      <td>15926.943359</td>\n",
       "      <td>3191.0</td>\n",
       "      <td>12735.943359</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         ID  label  ED_volume  time_from_start    time_gap        y_pred  \\\n",
       "0    sub001      0      48919       330.548947    2.500000  53620.218750   \n",
       "1    sub001      0      57898       330.789294    8.268333  53566.015625   \n",
       "2    sub001      0      81747       335.949294  126.340000  52399.144531   \n",
       "3    sub001      0     107793       341.267176  130.129167  52359.496094   \n",
       "4    sub001      0     126558       348.175544  168.300833  51968.328125   \n",
       "..      ...    ...        ...              ...         ...           ...   \n",
       "445  sub099      3      19517       885.972986   17.672778  28701.111328   \n",
       "446  sub099      3      30933       887.008681   27.856667  28645.626953   \n",
       "447  sub100      1       7367       786.766829    0.500000  15922.395508   \n",
       "448  sub100      1       6033       788.193125   34.731111  15923.831055   \n",
       "449  sub100      1       3191       794.964190  163.005556  15926.943359   \n",
       "\n",
       "      y_truth          diff  \n",
       "0     48919.0   4701.218750  \n",
       "1     57898.0  -4331.984375  \n",
       "2     81747.0 -29347.855469  \n",
       "3    107793.0 -55433.503906  \n",
       "4    126558.0 -74589.671875  \n",
       "..        ...           ...  \n",
       "445   19517.0   9184.111328  \n",
       "446   30933.0  -2287.373047  \n",
       "447    7367.0   8555.395508  \n",
       "448    6033.0   9890.831055  \n",
       "449    3191.0  12735.943359  \n",
       "\n",
       "[450 rows x 8 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "diff = data.groupby('ID').mean()['diff'].values\n",
    "data_fisrt = data.groupby('ID').first()\n",
    "data_fisrt['diff'] = diff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "# data_fisrt.to_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\q2_result0925.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "q3_data = pd.read_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\竞赛发布数据\\第三问b_2.xlsx')\n",
    "concat_data = pd.read_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\q3_total_data.xlsx')\n",
    "# q3_data['time_gap'] = concat_data['time_gap']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict_data = pd.read_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\竞赛发布数据\\第三问b_predict.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict_data.drop(['Unnamed: 0'], axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "need_col = q3_data.columns.tolist()\n",
    "# concat q3_data and predict data\n",
    "concat_data2 = pd.concat([q3_data, predict_data], axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "concat_data2.to_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\竞赛发布数据\\q3_b2_total.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "delete_col = '首次检查流水号'\n",
    "cols = concat_data2.columns.tolist()\n",
    "delete_col_index = cols.index(delete_col)\n",
    "delete_col = cols[delete_col_index:]\n",
    "concat_data2.drop(delete_col, axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "concat_data2.to_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\竞赛发布数据\\q3_b2_total.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data = pd.read_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\竞赛发布数据\\q3_b2_total.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Unnamed: 0'"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.columns[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer_data = pd.read_csv(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\q3_b_results\\q3_b_result.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['90天mRS', '90天mRS_all_feature', '90天mRS_top10'], dtype='object')"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "answer_data.columns[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "mode_pred = answer_data.groupby('ID')['90天mRS_top10'].apply(lambda x: x.mode().iloc[0]).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "mode_pred.to_excel(r'E:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\q3_b_results\\results.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4., 0., 5., 4., 3., 5., 2., 4., 3., 3., 1., 0., 1., 2., 2., 5., 3.,\n",
       "       0., 1., 2., 3., 2., 1., 1., 2., 3., 6., 4., 4., 5., 4., 0., 5., 4.,\n",
       "       5., 3., 3., 2., 1., 1., 3., 0., 5., 3., 1., 2., 1., 3., 1., 1., 0.,\n",
       "       3., 2., 3., 4., 0., 3., 5., 0., 4., 4., 2., 2., 3., 3., 6., 2., 2.,\n",
       "       6., 3., 1., 5., 1., 0., 3., 5., 6., 1., 1., 1., 3., 2., 5., 1., 2.,\n",
       "       0., 1., 2., 1., 5., 2., 5., 2., 5., 4., 4., 2., 5., 3., 2., 5., 1.,\n",
       "       5., 3., 1., 2., 3., 1., 4., 2., 4., 1., 2., 2., 2., 4., 2., 1., 1.,\n",
       "       0., 3., 2., 2., 1., 5., 2., 0., 1., 2.])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mode_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer_data_first = answer_data.groupby('ID').first().reindex()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "single positional indexer is out-of-bounds",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32me:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\代码\\q2_c_deal.ipynb 单元格 20\u001b[0m line \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X25sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m answer_data_first[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m answer_data\u001b[39m.\u001b[39;49mgroupby(\u001b[39m'\u001b[39;49m\u001b[39mID\u001b[39;49m\u001b[39m'\u001b[39;49m)[\u001b[39m'\u001b[39;49m\u001b[39m90天mRS\u001b[39;49m\u001b[39m'\u001b[39;49m]\u001b[39m.\u001b[39;49mapply(\u001b[39mlambda\u001b[39;49;00m x: x\u001b[39m.\u001b[39;49mmode()\u001b[39m.\u001b[39;49miloc[\u001b[39m0\u001b[39;49m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X25sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m answer_data_first[\u001b[39m'\u001b[39m\u001b[39m90天mRS_all_feature\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m answer_data\u001b[39m.\u001b[39mgroupby(\u001b[39m'\u001b[39m\u001b[39mID\u001b[39m\u001b[39m'\u001b[39m)[\u001b[39m'\u001b[39m\u001b[39m90天mRS_all_feature\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mapply(\u001b[39mlambda\u001b[39;00m x: x\u001b[39m.\u001b[39mmode()\u001b[39m.\u001b[39miloc[\u001b[39m0\u001b[39m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS_all_feature\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X25sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m answer_data_first[\u001b[39m'\u001b[39m\u001b[39m90天mRS_top10\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m answer_data\u001b[39m.\u001b[39mgroupby(\u001b[39m'\u001b[39m\u001b[39mID\u001b[39m\u001b[39m'\u001b[39m)[\u001b[39m'\u001b[39m\u001b[39m90天mRS_top10\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mapply(\u001b[39mlambda\u001b[39;00m x: x\u001b[39m.\u001b[39mmode()\u001b[39m.\u001b[39miloc[\u001b[39m0\u001b[39m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS_top10\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\generic.py:244\u001b[0m, in \u001b[0;36mSeriesGroupBy.apply\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m    238\u001b[0m \u001b[39m@Appender\u001b[39m(\n\u001b[0;32m    239\u001b[0m     _apply_docs[\u001b[39m\"\u001b[39m\u001b[39mtemplate\u001b[39m\u001b[39m\"\u001b[39m]\u001b[39m.\u001b[39mformat(\n\u001b[0;32m    240\u001b[0m         \u001b[39minput\u001b[39m\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mseries\u001b[39m\u001b[39m\"\u001b[39m, examples\u001b[39m=\u001b[39m_apply_docs[\u001b[39m\"\u001b[39m\u001b[39mseries_examples\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m    241\u001b[0m     )\n\u001b[0;32m    242\u001b[0m )\n\u001b[0;32m    243\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mapply\u001b[39m(\u001b[39mself\u001b[39m, func, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m--> 244\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mapply(func, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\groupby.py:1423\u001b[0m, in \u001b[0;36mGroupBy.apply\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m   1421\u001b[0m \u001b[39mwith\u001b[39;00m option_context(\u001b[39m\"\u001b[39m\u001b[39mmode.chained_assignment\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39mNone\u001b[39;00m):\n\u001b[0;32m   1422\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m-> 1423\u001b[0m         result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_python_apply_general(f, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_selected_obj)\n\u001b[0;32m   1424\u001b[0m     \u001b[39mexcept\u001b[39;00m \u001b[39mTypeError\u001b[39;00m:\n\u001b[0;32m   1425\u001b[0m         \u001b[39m# gh-20949\u001b[39;00m\n\u001b[0;32m   1426\u001b[0m         \u001b[39m# try again, with .apply acting as a filtering\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1430\u001b[0m         \u001b[39m# fails on *some* columns, e.g. a numeric operation\u001b[39;00m\n\u001b[0;32m   1431\u001b[0m         \u001b[39m# on a string grouper column\u001b[39;00m\n\u001b[0;32m   1433\u001b[0m         \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_group_selection_context():\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\groupby.py:1464\u001b[0m, in \u001b[0;36mGroupBy._python_apply_general\u001b[1;34m(self, f, data, not_indexed_same)\u001b[0m\n\u001b[0;32m   1438\u001b[0m \u001b[39m@final\u001b[39m\n\u001b[0;32m   1439\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_python_apply_general\u001b[39m(\n\u001b[0;32m   1440\u001b[0m     \u001b[39mself\u001b[39m,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1443\u001b[0m     not_indexed_same: \u001b[39mbool\u001b[39m \u001b[39m|\u001b[39m \u001b[39mNone\u001b[39;00m \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m,\n\u001b[0;32m   1444\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m DataFrame \u001b[39m|\u001b[39m Series:\n\u001b[0;32m   1445\u001b[0m \u001b[39m    \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m   1446\u001b[0m \u001b[39m    Apply function f in python space\u001b[39;00m\n\u001b[0;32m   1447\u001b[0m \n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1462\u001b[0m \u001b[39m        data after applying f\u001b[39;00m\n\u001b[0;32m   1463\u001b[0m \u001b[39m    \"\"\"\u001b[39;00m\n\u001b[1;32m-> 1464\u001b[0m     values, mutated \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgrouper\u001b[39m.\u001b[39;49mapply(f, data, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49maxis)\n\u001b[0;32m   1466\u001b[0m     \u001b[39mif\u001b[39;00m not_indexed_same \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m   1467\u001b[0m         not_indexed_same \u001b[39m=\u001b[39m mutated \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmutated\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\ops.py:761\u001b[0m, in \u001b[0;36mBaseGrouper.apply\u001b[1;34m(self, f, data, axis)\u001b[0m\n\u001b[0;32m    759\u001b[0m \u001b[39m# group might be modified\u001b[39;00m\n\u001b[0;32m    760\u001b[0m group_axes \u001b[39m=\u001b[39m group\u001b[39m.\u001b[39maxes\n\u001b[1;32m--> 761\u001b[0m res \u001b[39m=\u001b[39m f(group)\n\u001b[0;32m    762\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m mutated \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m _is_indexed_like(res, group_axes, axis):\n\u001b[0;32m    763\u001b[0m     mutated \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n",
      "\u001b[1;32me:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\代码\\q2_c_deal.ipynb 单元格 20\u001b[0m line \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X25sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m answer_data_first[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m answer_data\u001b[39m.\u001b[39mgroupby(\u001b[39m'\u001b[39m\u001b[39mID\u001b[39m\u001b[39m'\u001b[39m)[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mapply(\u001b[39mlambda\u001b[39;00m x: x\u001b[39m.\u001b[39;49mmode()\u001b[39m.\u001b[39;49miloc[\u001b[39m0\u001b[39;49m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X25sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m answer_data_first[\u001b[39m'\u001b[39m\u001b[39m90天mRS_all_feature\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m answer_data\u001b[39m.\u001b[39mgroupby(\u001b[39m'\u001b[39m\u001b[39mID\u001b[39m\u001b[39m'\u001b[39m)[\u001b[39m'\u001b[39m\u001b[39m90天mRS_all_feature\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mapply(\u001b[39mlambda\u001b[39;00m x: x\u001b[39m.\u001b[39mmode()\u001b[39m.\u001b[39miloc[\u001b[39m0\u001b[39m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS_all_feature\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X25sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m answer_data_first[\u001b[39m'\u001b[39m\u001b[39m90天mRS_top10\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m answer_data\u001b[39m.\u001b[39mgroupby(\u001b[39m'\u001b[39m\u001b[39mID\u001b[39m\u001b[39m'\u001b[39m)[\u001b[39m'\u001b[39m\u001b[39m90天mRS_top10\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mapply(\u001b[39mlambda\u001b[39;00m x: x\u001b[39m.\u001b[39mmode()\u001b[39m.\u001b[39miloc[\u001b[39m0\u001b[39m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS_top10\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:967\u001b[0m, in \u001b[0;36m_LocationIndexer.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m    964\u001b[0m axis \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39maxis \u001b[39mor\u001b[39;00m \u001b[39m0\u001b[39m\n\u001b[0;32m    966\u001b[0m maybe_callable \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mapply_if_callable(key, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj)\n\u001b[1;32m--> 967\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_getitem_axis(maybe_callable, axis\u001b[39m=\u001b[39;49maxis)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1523\u001b[0m, in \u001b[0;36m_iLocIndexer._getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1520\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mCannot index by location index with a non-integer key\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m   1522\u001b[0m \u001b[39m# validate the location\u001b[39;00m\n\u001b[1;32m-> 1523\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_validate_integer(key, axis)\n\u001b[0;32m   1525\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj\u001b[39m.\u001b[39m_ixs(key, axis\u001b[39m=\u001b[39maxis)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1455\u001b[0m, in \u001b[0;36m_iLocIndexer._validate_integer\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1453\u001b[0m len_axis \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj\u001b[39m.\u001b[39m_get_axis(axis))\n\u001b[0;32m   1454\u001b[0m \u001b[39mif\u001b[39;00m key \u001b[39m>\u001b[39m\u001b[39m=\u001b[39m len_axis \u001b[39mor\u001b[39;00m key \u001b[39m<\u001b[39m \u001b[39m-\u001b[39mlen_axis:\n\u001b[1;32m-> 1455\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mIndexError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39msingle positional indexer is out-of-bounds\u001b[39m\u001b[39m\"\u001b[39m)\n",
      "\u001b[1;31mIndexError\u001b[0m: single positional indexer is out-of-bounds"
     ]
    }
   ],
   "source": [
    "answer_data_first['90天mRS'] = answer_data.groupby('ID')['90天mRS'].apply(lambda x: x.mode().iloc[0]).reset_index()['90天mRS'].values\n",
    "answer_data_first['90天mRS_all_feature'] = answer_data.groupby('ID')['90天mRS_all_feature'].apply(lambda x: x.mode().iloc[0]).reset_index()['90天mRS_all_feature'].values\n",
    "answer_data_first['90天mRS_top10'] = answer_data.groupby('ID')['90天mRS_top10'].apply(lambda x: x.mode().iloc[0]).reset_index()['90天mRS_top10'].values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "single positional indexer is out-of-bounds",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32me:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\代码\\q2_c_deal.ipynb 单元格 21\u001b[0m line \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X26sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m answer_data\u001b[39m.\u001b[39;49mgroupby(\u001b[39m'\u001b[39;49m\u001b[39mID\u001b[39;49m\u001b[39m'\u001b[39;49m)[\u001b[39m'\u001b[39;49m\u001b[39m90天mRS\u001b[39;49m\u001b[39m'\u001b[39;49m]\u001b[39m.\u001b[39;49mapply(\u001b[39mlambda\u001b[39;49;00m x: x\u001b[39m.\u001b[39;49mmode()\u001b[39m.\u001b[39;49miloc[\u001b[39m0\u001b[39;49m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\generic.py:244\u001b[0m, in \u001b[0;36mSeriesGroupBy.apply\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m    238\u001b[0m \u001b[39m@Appender\u001b[39m(\n\u001b[0;32m    239\u001b[0m     _apply_docs[\u001b[39m\"\u001b[39m\u001b[39mtemplate\u001b[39m\u001b[39m\"\u001b[39m]\u001b[39m.\u001b[39mformat(\n\u001b[0;32m    240\u001b[0m         \u001b[39minput\u001b[39m\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mseries\u001b[39m\u001b[39m\"\u001b[39m, examples\u001b[39m=\u001b[39m_apply_docs[\u001b[39m\"\u001b[39m\u001b[39mseries_examples\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m    241\u001b[0m     )\n\u001b[0;32m    242\u001b[0m )\n\u001b[0;32m    243\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mapply\u001b[39m(\u001b[39mself\u001b[39m, func, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m--> 244\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39mapply(func, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\groupby.py:1423\u001b[0m, in \u001b[0;36mGroupBy.apply\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m   1421\u001b[0m \u001b[39mwith\u001b[39;00m option_context(\u001b[39m\"\u001b[39m\u001b[39mmode.chained_assignment\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39mNone\u001b[39;00m):\n\u001b[0;32m   1422\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m-> 1423\u001b[0m         result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_python_apply_general(f, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_selected_obj)\n\u001b[0;32m   1424\u001b[0m     \u001b[39mexcept\u001b[39;00m \u001b[39mTypeError\u001b[39;00m:\n\u001b[0;32m   1425\u001b[0m         \u001b[39m# gh-20949\u001b[39;00m\n\u001b[0;32m   1426\u001b[0m         \u001b[39m# try again, with .apply acting as a filtering\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1430\u001b[0m         \u001b[39m# fails on *some* columns, e.g. a numeric operation\u001b[39;00m\n\u001b[0;32m   1431\u001b[0m         \u001b[39m# on a string grouper column\u001b[39;00m\n\u001b[0;32m   1433\u001b[0m         \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_group_selection_context():\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\groupby.py:1464\u001b[0m, in \u001b[0;36mGroupBy._python_apply_general\u001b[1;34m(self, f, data, not_indexed_same)\u001b[0m\n\u001b[0;32m   1438\u001b[0m \u001b[39m@final\u001b[39m\n\u001b[0;32m   1439\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_python_apply_general\u001b[39m(\n\u001b[0;32m   1440\u001b[0m     \u001b[39mself\u001b[39m,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1443\u001b[0m     not_indexed_same: \u001b[39mbool\u001b[39m \u001b[39m|\u001b[39m \u001b[39mNone\u001b[39;00m \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m,\n\u001b[0;32m   1444\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m DataFrame \u001b[39m|\u001b[39m Series:\n\u001b[0;32m   1445\u001b[0m \u001b[39m    \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m   1446\u001b[0m \u001b[39m    Apply function f in python space\u001b[39;00m\n\u001b[0;32m   1447\u001b[0m \n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1462\u001b[0m \u001b[39m        data after applying f\u001b[39;00m\n\u001b[0;32m   1463\u001b[0m \u001b[39m    \"\"\"\u001b[39;00m\n\u001b[1;32m-> 1464\u001b[0m     values, mutated \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgrouper\u001b[39m.\u001b[39;49mapply(f, data, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49maxis)\n\u001b[0;32m   1466\u001b[0m     \u001b[39mif\u001b[39;00m not_indexed_same \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m   1467\u001b[0m         not_indexed_same \u001b[39m=\u001b[39m mutated \u001b[39mor\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmutated\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\ops.py:761\u001b[0m, in \u001b[0;36mBaseGrouper.apply\u001b[1;34m(self, f, data, axis)\u001b[0m\n\u001b[0;32m    759\u001b[0m \u001b[39m# group might be modified\u001b[39;00m\n\u001b[0;32m    760\u001b[0m group_axes \u001b[39m=\u001b[39m group\u001b[39m.\u001b[39maxes\n\u001b[1;32m--> 761\u001b[0m res \u001b[39m=\u001b[39m f(group)\n\u001b[0;32m    762\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m mutated \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m _is_indexed_like(res, group_axes, axis):\n\u001b[0;32m    763\u001b[0m     mutated \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n",
      "\u001b[1;32me:\\\23研赛\\建模2023\\建模2023\\2023年中国研究生数学建模竞赛赛题\\E题\\E题\\第三问\\代码\\q2_c_deal.ipynb 单元格 21\u001b[0m line \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/e%3A/%E5%A4%96%E5%8C%85%E4%BD%9C%E4%B8%9A/23%E7%A0%94%E8%B5%9B/%E5%BB%BA%E6%A8%A12023/%E5%BB%BA%E6%A8%A12023/2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E7%A0%94%E7%A9%B6%E7%94%9F%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1%E7%AB%9E%E8%B5%9B%E8%B5%9B%E9%A2%98/E%E9%A2%98/E%E9%A2%98/%E7%AC%AC%E4%B8%89%E9%97%AE/%E4%BB%A3%E7%A0%81/q2_c_deal.ipynb#X26sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m answer_data\u001b[39m.\u001b[39mgroupby(\u001b[39m'\u001b[39m\u001b[39mID\u001b[39m\u001b[39m'\u001b[39m)[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mapply(\u001b[39mlambda\u001b[39;00m x: x\u001b[39m.\u001b[39;49mmode()\u001b[39m.\u001b[39;49miloc[\u001b[39m0\u001b[39;49m])\u001b[39m.\u001b[39mreset_index()[\u001b[39m'\u001b[39m\u001b[39m90天mRS\u001b[39m\u001b[39m'\u001b[39m]\u001b[39m.\u001b[39mvalues\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:967\u001b[0m, in \u001b[0;36m_LocationIndexer.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m    964\u001b[0m axis \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39maxis \u001b[39mor\u001b[39;00m \u001b[39m0\u001b[39m\n\u001b[0;32m    966\u001b[0m maybe_callable \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mapply_if_callable(key, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj)\n\u001b[1;32m--> 967\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_getitem_axis(maybe_callable, axis\u001b[39m=\u001b[39;49maxis)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1523\u001b[0m, in \u001b[0;36m_iLocIndexer._getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1520\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mCannot index by location index with a non-integer key\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m   1522\u001b[0m \u001b[39m# validate the location\u001b[39;00m\n\u001b[1;32m-> 1523\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_validate_integer(key, axis)\n\u001b[0;32m   1525\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj\u001b[39m.\u001b[39m_ixs(key, axis\u001b[39m=\u001b[39maxis)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:1455\u001b[0m, in \u001b[0;36m_iLocIndexer._validate_integer\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1453\u001b[0m len_axis \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mobj\u001b[39m.\u001b[39m_get_axis(axis))\n\u001b[0;32m   1454\u001b[0m \u001b[39mif\u001b[39;00m key \u001b[39m>\u001b[39m\u001b[39m=\u001b[39m len_axis \u001b[39mor\u001b[39;00m key \u001b[39m<\u001b[39m \u001b[39m-\u001b[39mlen_axis:\n\u001b[1;32m-> 1455\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mIndexError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39msingle positional indexer is out-of-bounds\u001b[39m\u001b[39m\"\u001b[39m)\n",
      "\u001b[1;31mIndexError\u001b[0m: single positional indexer is out-of-bounds"
     ]
    }
   ],
   "source": [
    "answer_data.groupby('ID')['90天mRS'].apply(lambda x: x.mode().iloc[0]).reset_index()['90天mRS'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
